package ca.etsmtl.log430.lab2;

/**
 * This class displays lists (StudentList and CourseList objects).
 * 
 * A variety of methods are provided that display Student object, Course
 * objects, StudentList objects, and CourseList objects to the terminal.
 * 
 * @author A.J. Lattanze, CMU
 * @version 1.2, 2011-Feb-02
 */

/*
 * Modification Log
 * ************************************************************************
 * v1.2, 2011-Feb-02, R. Champagne - Various refactorings, javadoc comments.
 * 
 * v1.1, 2002-May-21, R. Champagne - Adapted for use at ETS.
 * 
 * v1.0, 12/29/99, A.J. Lattanze - Original version.
 * ************************************************************************
 */

public class Displays {

	private int lineCount = 0;
	private int maxLinesDisplayed = 18;

	/**
	 * Counts the number of lines that has been printed. One a set number of
	 * lines has been printed, the user is asked to press the enter key to
	 * continue. This prevents lines of text from scrolling off of the page
	 * 
	 * @param LinesToAdd
	 */
	private void lineCheck(int LinesToAdd) {

		Termio Terminal = new Termio();

		if (lineCount >= maxLinesDisplayed) {

			lineCount = 0;
			System.out.print("\n*** Press Enter To Continue ***");
			Terminal.keyboardReadChar();

		} else {

			lineCount += LinesToAdd;

		} // if

	} // LineCheck

	/**
	 * Displays a student object elements as follows: Student's first name,
	 * Student's last name, Student's ID number, Student's program affiliation
	 * (e.g. LOG, CGL, ELE, etc.)
	 * 
	 * Note that the courses taken by the student are not listed and the courses
	 * the student has registered for are not listed.
	 * 
	 * @param StudentObject
	 */
	public void displayStudent(Student StudentObject) {

		System.out.print(StudentObject.getStudentID() + " "
				+ StudentObject.getFirstName() + " ");
		System.out
				.println(StudentObject.getLastName() + " " + StudentObject.getProgram());

	} // DisplayStudent

	/**
	 * Displays a course object elements as follows: Course title, Course
	 * number, Course section (group), Days the course will be held on, Start
	 * time of the course, Stop time of the course, Instructor Name. Note that
	 * the students registered for the course are not listed by this method.
	 * 
	 * @param CourseObject
	 */
	public void displayCourse(Course CourseObject) {

		System.out.print(CourseObject.getCourseID() + " "
				+ CourseObject.getSection() + " ");
		System.out.print(CourseObject.getCourseName() + " "
				+ CourseObject.getDays() + " ");
		System.out.print(CourseObject.getStartTime() + ":"
				+ CourseObject.getStopTime() + " ");
		System.out.println(CourseObject.getInstructor());

	} // DisplayCourse

	/**
	 * Lists the students that have registered for the course.
	 * 
	 * @param CourseObject
	 */
	public void displayStudentsRegistered(Course CourseObject) {

		boolean Done;
		Student StudentObject;

		System.out.println("\nStudents Registered For: " + " ");
		lineCheck(2);

		System.out.print(CourseObject.getCourseName() + " "
				+ CourseObject.getCourseID() + " ");
		System.out.print(CourseObject.getSection() + " "
				+ CourseObject.getDays() + " ");
		System.out.print(CourseObject.getStartTime() + ":"
				+ CourseObject.getStopTime() + " ");
		System.out.println(CourseObject.getInstructor());
		lineCheck(1);

		System.out
				.println("===========================================================");
		lineCheck(1);

		CourseObject.getRegisteredStudents().goToFrontOfList();
		Done = false;

		while (!Done) {

			StudentObject = CourseObject.getRegisteredStudents()
					.getNextStudent();

			if (StudentObject == null) {

				Done = true;

			} else {

				displayStudent(StudentObject);

			} // if

		} // while

	} // DisplayStudentsRegistered

	/**
	 * Lists the courses that the student has registered for.
	 * 
	 * @param StudentObject
	 */
	public void displayStudentCoursesRegistered(Student StudentObject) {

		boolean Done;
		Course CourseObject;

		System.out.print("\nCourses Registered For: " + StudentObject.getFirstName()
				+ " ");
		System.out.println(StudentObject.getLastName() + " "
				+ StudentObject.getStudentID());
		lineCheck(2);
		System.out
				.println("==================================================== ");
		lineCheck(1);

		StudentObject.getCoursesRegistered().goToFrontOfList();
		Done = false;

		while (!Done) {

			CourseObject = StudentObject.getCoursesRegistered().getNextCourse();

			if (CourseObject == null) {

				Done = true;

			} else {

				displayCourse(CourseObject);
				lineCheck(2);

			} // if

		} // while

	} // DisplayStudentCoursesRegistered

	/**
	 * Lists the courses that the student has taken.
	 * 
	 * @param StudentObject
	 */
	public void displayStudentCoursesTaken(Student StudentObject) {

		boolean Done;
		Course CourseObject;

		System.out.print("\nCourses Taken: " + StudentObject.getFirstName() + " ");
		System.out.println(StudentObject.getLastName() + " "
				+ StudentObject.getStudentID());
		lineCheck(2);
		System.out.println("================================================ ");
		lineCheck(1);

		StudentObject.getCoursesTakenList().goToFrontOfList();
		Done = false;

		while (!Done) {

			CourseObject = StudentObject.getCoursesTakenList().getNextCourse();

			if (CourseObject == null) {

				Done = true;

			} else {

				System.out.println(CourseObject.getCourseID());
				lineCheck(1);

			} // if

		} // while

	} // DisplayStudentCoursesTaken

	/**
	 * TP2: CHRISTIAN POINT 2
	 * 
	 * Lists the course requirement missing for the student.
	 * 
	 * @param StudentObject
	 */
	public void displayStudentRequirementCoursesMissing(Student StudentObject) {

		boolean Done;
		Course CourseObject;

		CourseList req = StudentObject.GenerateMissingCoursesRequirements();
		
		System.out.print("\nMissing requirements: " + StudentObject.getFirstName() + " ");
		System.out.println(StudentObject.getLastName() + " "
				+ StudentObject.getStudentID());
		lineCheck(2);
		System.out.println("================================================ ");
		lineCheck(1);

		req.goToFrontOfList();
		Done = false;

		while (!Done) {

			CourseObject = req.getNextCourse();

			if (CourseObject == null) {

				Done = true;

			} else {

				System.out.print(CourseObject.getCourseID());
				lineCheck(1);

			} // if

		} // while

	} // DisplayStudentCoursesTaken	
	
	
	/**
	 * Displays the students in the student list. Displays the same information
	 * that is listed in the displayStudent() method listed above.
	 * 
	 * @param ListObject
	 */
	public void displayStudentList(StudentList ListObject) {

		boolean Done;
		Student StudentObject;

		System.out.print("\n");
		lineCheck(1);

		ListObject.goToFrontOfList();

		Done = false;

		while (!Done) {

			StudentObject = ListObject.getNextStudent();

			if (StudentObject == null) {

				Done = true;

			} else {

				displayStudent(StudentObject);
				lineCheck(1);

			} // if

		} // while

	} // DisplayStudentList

	/**
	 * Displays the courses in the course list. Displays the same information
	 * that is listed in the displayCourse() method listed above.
	 * 
	 * @param ListObject
	 */
	public void displayCourseList(CourseList ListObject) {

		boolean Done;
		Course CourseObject;

		System.out.print("\n");
		lineCheck(1);

		ListObject.goToFrontOfList();
		Done = false;

		while (!Done) {

			CourseObject = ListObject.getNextCourse();

			if (CourseObject == null) {

				Done = true;

			} else {

				displayCourse(CourseObject);
				lineCheck(1);

			} // if

		} // while

	} // DisplayCourseList

} // Display